//
//  CFProgressHUD.m
//  CareFuture
//
//  Created by 许洋 on 2018/5/10.
//  Copyright © 2018年 zjab. All rights reserved.
//

#import "CFProgressHUD.h"
#import <MBProgressHUD/MBProgressHUD.h>
#import "CFGetViewUtils.h"
@interface CFProgressHUD()
@property (nonatomic,strong) MBProgressHUD *hud;

@end
@implementation CFProgressHUD
static MBProgressHUD *_hud;
+ (void)showSuccess:(NSString *)success
{
    if (!_hud) {
        _hud=[[MBProgressHUD alloc]initWithView:[CFGetViewUtils topController ].view];
    }
    if (!_hud.superview) {
        [[CFGetViewUtils topController ].view addSubview:_hud];
    }
    _hud.mode=MBProgressHUDModeText;
    _hud.label.text = success;
    [_hud showAnimated:YES];
    [_hud hideAnimated:YES afterDelay:2];
   
}
+ (void)showError:(NSString *)error
{
    [self showError:error afterDelay:2];
}
+ (void)showError:(NSString *)error afterDelay:(NSTimeInterval )afterDelay{
    if (!_hud) {
        _hud=[[MBProgressHUD alloc]initWithView:[CFGetViewUtils topController ].view];
    }
    if (!_hud.superview) {
        [[CFGetViewUtils topController ].view addSubview:_hud];
    }
    _hud.mode=MBProgressHUDModeText;
    _hud.label.text = error;
    [_hud showAnimated:YES];
    [_hud hideAnimated:YES afterDelay:afterDelay];
}

+ (void)showMessage:(NSString *)message
{
    [self showMessage:message afterDelay:3];
}
+ (void)showMessage:(NSString *)message afterDelay:(NSTimeInterval )afterDelay{
    if (!_hud) {
        _hud=[[MBProgressHUD alloc]initWithView:[CFGetViewUtils topController ].view];
    }
    if (!_hud.superview) {
        [[CFGetViewUtils topController ].view addSubview:_hud];
    }
    _hud.mode=MBProgressHUDModeText;
    _hud.label.text = message;
    [_hud showAnimated:YES];
    [_hud hideAnimated:YES afterDelay:afterDelay];
}

+ (void)showWaiting
{
    if (!_hud) {
        _hud=[[MBProgressHUD alloc]initWithView:[CFGetViewUtils topController ].view];
    }
    if (!_hud.superview) {
        [[CFGetViewUtils topController ].view addSubview:_hud];
    }
    _hud.label.text = @"";
    _hud.mode = MBProgressHUDModeIndeterminate;
    [_hud showAnimated:YES];
}
+ (void)showLoading
{
    [self showLoadingWithMessage:@"正在加载"];
}
+ (void)showLoadingWithMessage:(NSString *)message
{
    if (!_hud) {
        _hud=[[MBProgressHUD alloc]initWithView:[CFGetViewUtils topController ].view];
    }
    if (!_hud.superview) {
        [[CFGetViewUtils topController ].view addSubview:_hud];
    }
    _hud.mode = MBProgressHUDModeIndeterminate;
    _hud.label.text = message;
    [_hud showAnimated:YES];

}
+ (void)showSaving
{
    if (!_hud) {
        _hud=[[MBProgressHUD alloc]initWithView:[CFGetViewUtils topController ].view];
    }
    if (!_hud.superview) {
        [[CFGetViewUtils topController ].view addSubview:_hud];
    }
  
    _hud.mode = MBProgressHUDModeIndeterminate;
    _hud.label.text = @"正在保存";
    [_hud showAnimated:YES];
}
+ (void)hideHUD
{
    [MBProgressHUD hideHUDForView:[CFGetViewUtils topController ].view animated:YES];
}

@end
